package com.campus.marketplace.repository;

import com.campus.marketplace.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {
    List<Comment> findByProductIdAndParentIsNullOrderByCreatedAtDesc(Long productId);
    
    List<Comment> findByParentIdOrderByCreatedAtAsc(Long parentId);
    
    @Query("SELECT c FROM Comment c WHERE c.product.id = :productId AND c.level = :level")
    List<Comment> findByProductIdAndLevel(@Param("productId") Long productId, @Param("level") Integer level);
    
    @Query("SELECT COUNT(c) FROM Comment c WHERE c.product.id = :productId")
    Long countByProductId(@Param("productId") Long productId);
    
    List<Comment> findByStatus(String status);
} 